package element.synt;

import ast.AstItem;
import ast.BlockStatement;
import ast.FuncDef;
import ast.FunctionSignature;
import element.base.Synt;

import java.util.List;

public class ConstructorDef extends Synt {
    @Override
    public AstItem toAst() {
        FuncDef funcDef = new FuncDef();
        FunctionSignature head = new FunctionSignature();
        head.signatureType = FunctionSignature.SignatureType.CLASS_CONSTRUCTOR;
        if (getNodes().size() == 5) {
            FuncFParams fParams = (FuncFParams) getNodes().get(2);
            List<AstItem> params = fParams.toAsts();
            for (AstItem param: params) {
                head.parameters.add(param);
            }
        }
        funcDef.funcSignature = head;
        Block block = (Block) getNodes().getLast();
        AstItem blockStatement = block.toAst();
        funcDef.funcBlock = blockStatement;

        return funcDef;
    }
}
